package Methods;

import SpotTable.SpotTable;
import TripleTable.TripleTable;

public class InitializeTripleTable {
    TripleTable path;

    public TripleTable initializeTripleTable(SpotTable spot){//通过景点信息生成三元组表
        int[] id1 = new int[spot.length()];
        int[][] adj = new int[spot.length()][spot.length()];
        String temp;
        for (int i = 0; i < spot.length(); i++) {//将spot.adj中记录的邻接关系转化为整型数组
            id1[i] = spot.getId(i);
            temp = String.valueOf(spot.turnAdj2Seq(spot.getAdj(i)));
            for (int j = 0; j < temp.length(); j++) {//将adj转化为整型
                adj[i][j] = temp.charAt(j);
            }
        }
        for (int i = 0; i < spot.length(); i++) {//遍历每个景点的adj
            for (int j = 0; j < spot.length(); j += 2) {//将路径赋给三元组表
                this.path.insert(id1[i], adj[i][j], adj[i][j+1]);
            }
        }
        return this.path;//返回三元组表
    }
}
